package com.lzyjkz.quick_system.enums.machine;

import lombok.Getter;

@Getter
public enum CPUWarnValueEnum {

    LEVEL_0((double) Integer.MIN_VALUE, 0),
    LEVEL_1(0.0, 1),
    LEVEL_2(0.85, 2),
    LEVEL_3(0.95, 3);
    // CPU预警使用率阈值
    private final Double value;
    // 预警级别
    private final Integer code;
    CPUWarnValueEnum(Double value, Integer code) {
        this.value = value;
        this.code = code;
    }

    public static CPUWarnValueEnum getLevelByValue(Double value) {
        for (int i = CPUWarnValueEnum.values().length; i >= 0; i--) {
            // 预警阈值小于等于value时返回
            CPUWarnValueEnum value1 = CPUWarnValueEnum.values()[i - 1];
            if (value1.value <= value) {
                return CPUWarnValueEnum.values()[i - 1];
            }
        }
        return null;
    }
}
